package com.luozongyao.statistics.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.luozongyao.commons.R;
import com.luozongyao.statistics.entity.Statistic;
import com.luozongyao.statistics.service.StatisticService;
import com.luozongyao.videoPromotion.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luozongyao
 * @since 2021-11-13
 */
@Api(description="信息统计管理")
@RestController
@RequestMapping("/statistics/statistic")
@CrossOrigin
public class StatisticController {

    @Autowired
    private RedisTemplate stringRedisTemplate;

    @Autowired
    private StatisticService statisticService;

    @Autowired
    private VideoService videoService;



    //统计某天注册人数 视频发布数 视频举报数 用户举报数
    @ApiOperation(value = "统计某天注册人数 登录人数 视频发布数 视频举报数 用户举报数")
    @PostMapping("statisticCount/{day}")
    public R statisticCount(@PathVariable String day){
        statisticService.statisticCount(day);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("statistic_date",day);
        Statistic statistic =  statisticService.getOne(queryWrapper);
        return R.ok().data("statistic",statistic);
    }

    //图表显示，返回两部分数据，日期json数组，数量json数组
    @ApiOperation(value="获取图表所需信息 返回日期json数组和数量json数组")
    @GetMapping("getChartData/{type}/{begin}/{end}")
    public R getChartData(@PathVariable String type,@PathVariable String begin,@PathVariable(required = false) String end){
        Map<String, Object> map = statisticService.getChartData(type,begin,end);
        return R.ok().data(map);
    }

    

}

